package com.bckj.fastboot.upms.biz.mapper;

import com.bckj.fastboot.upms.api.dto.UserAuthInfo;
import com.bckj.fastboot.upms.api.entity.User;
import com.bckj.fastboot.upms.api.vo.UserVO;
import com.bckj.fastboot.upms.api.dto.UserQuery;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;

/**
 * 用户表(User)表数据库访问层
 *
 * @author wfc
 * @since 2023-09-14 16:05:36
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    /**
      * 列表
      *
      * @param query req
      * @return list
      */
    @SelectProvider(method = "list" , type = UserProvider.class)
    List<UserVO> list(UserQuery query);

    @Select("""
    select id, phone,phone username,phone password,true enabled,true accountNonExpired,true credentialsNonExpired,true accountNonLocked from user where phone=#{phone} and delete_flag=0
    """)
    UserAuthInfo findByPhone(@Param("phone") String phone);

    class UserProvider{
        
        public String list(UserQuery query){
            return new SQL(){{
                SELECT("id, phone, gender, head_img, nickname, version, delete_flag, create_time, update_time");
                FROM("user");
                ORDER_BY("id DESC");
            }}.toString();
        }
    }
}

